﻿@{
    ViewBag.Title = "Ins";
}
@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>  
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
<body>
   <form id="form1" runat="server" method="post" style="height: 100%">    
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" id="refresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="checkbill" name="checkbill" iconCls="icon-remove" onclick="checkBill" plain="true">审核</a>                
                    <span class="separator"></span>
                    <a class="mini-button" id="export" iconCls="icon-node" onclick="setExportExcel('datagrid1')"plain="true">导出</a>
                    <a class="mini-button" id="print" iconCls="icon-print" onclick="printdata" plain="true">打印</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>                
    </div>    
    <div id = "DivHeader">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">单据日期：</td>
                <td width ="320px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="70px" align="right">商户名称：</td>
                <td width ="190px">    
                     @Html.Partial("~/Views/Modular/LookupCorpInfo.cshtml")                      
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td width ="70px" align="right">订单搜索：</td>
                <td width ="160px">
                    <input name="FBillNo" class="mini-textbox" style="width:160px;"/>
                </td>
                <td width ="70px" align="right">审核状态：</td>
                <td width ="80px">
                    <input id="comCheckFlag" name ="FCheckFlag" class="mini-combobox" style="width:70px;" 
                    showNullItem="false" required="true" allowInput="false" align="left" data ="dCheckFlag"/>  
                </td>
                <td width ="70px" align="right">公司名称：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupCorpClassInfo.cshtml") 
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" borderStyle="border:1;"pageSize="15"
            url="../Report/GetBillList"
            allowCellSelect="true" allowCellEdit="true" showSummaryRow="true" ondrawsummarycell="onDrawSummaryCell"
            fitColumns="false" onrowdblclick="editBill" sortMode="client" onselectionchanged="onSelectionChanged">
            <div property="columns">
                <div type="checkcolumn" ></div>  
                <div field="FBillNo" width="120" headerAlign="center">单据编号</div>    
                <div field="FDate" name="FDate" width="130px" dateFormat="yyyy-MM-dd hh:mm:ss" headerAlign="center">单据日期</div>      
                <div field="FRebateAmount" name="FRebateAmount" width="90" headerAlign="center" align="right" numberFormat="#,0.00">申请时余额</div>          
                <div field="FAmount" name="FAmount" width="90" headerAlign="center" align="right" numberFormat="#,0.00">申请金额</div>
                <div field="FCheckAmount" name="FCheckAmount" width="90" headerAlign="center" align="right" numberFormat="#,0.00">转帐金额</div>
                <div field="FCheckName" width="70" headerAlign="center">审核标志</div>
                <div field="FBankUser" width="80" headerAlign="center">收款人</div>
                <div field="FBankName" width="150" headerAlign="center">开户行</div>
                <div field="FBankNo" width="150" headerAlign="center">银行帐号</div>
                <div field="FName" width="150" headerAlign="center">店铺名称</div>
                <div field="FTelephone" width="100" headerAlign="center">联系电话</div>
                <div field="FExplanation" width="120" headerAlign="center">摘要</div>    
            </div>
        </div>  
    </div>
    
    <script type="text/javascript">

        var dCheckFlag = [{ "id": "0", "text": "全部" },
                         { "id": "1", "text": "未审核" },
                         { "id": "2", "text": "已审核" }]

        mini.parse();
        var form = new mini.Form("form1");
        var grid = mini.get("datagrid1");
        var uID = parent.window.getSystemAppID();
        var hdatatype = getQueryString("datatype");
        var sumFields = "FCheckAmount,FAmount";

        function FormShown() {
            var nowDate = new Date();
            mini.getbyName("FDate1").setValue(nowDate);
            mini.getbyName("FDate2").setValue(nowDate);
            mini.getbyName("FCheckFlag").select(1);
            search();
        }

        function editBill() {
            var row = grid.getSelected();
            if (row) {
                var mDataType = row.FDataType;
                if (mDataType == 5) {
                    parent.window.showTabByIdEx('77','MallData', '订单管理', '../Bill/MallData?datatype=5&billid=' + row.KInterID);
                }
            }
        }

        function checkBill() {
            var row = grid.getSelected();
            if (row) {
                var mCheckFlag = row.FCheckFlag;
                if (!mCheckFlag) {
                    mini.confirm("确定要删除该单据吗？", "提示",
                        function (action) {
                            if (action == "ok") {
                                SetRemoveBill(row);
                            }
                        }
                   );
                }
                else {
                    mini.alert("已审核的单据不能删除!");
                }
            }
        }

        function SetRemoveBill(row) {
            var json = "[{";
            json = json + "'KInterID':'" + row.KInterID + "',";
            json = json + "'FDataType':'" + row.FDataType + "',";
            json = json + "'FSystemAppID':'" + uID + "'}]";
            $.ajax({
                url: '../Bill/RemoveBillData',
                data: { mdatajson: json },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    if (ret.id != -1) {
                        grid.removeRow(row, true);
                        mini.showMessageBox({
                            showModal: false, width: 250, title: "提示", iconCls: "mini-messagebox-info",
                            message: ret.Status, timeout: 3000, x: "right", y: "bottom"
                        });
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }

        function search() {
            var cDate1 = mini.getbyName("FDate1").getFormValue();
            var cDate2 = mini.getbyName("FDate2").getFormValue();
            var mCheckFlag = mini.getbyName("FCheckFlag").getValue();
            var mBillNo = mini.getbyName("FBillNo").getValue();
            var mCorpItemID = mini.getbyName("FCorpItemID").getValue();
            var mCorpClassID = mini.getbyName("FCorpClassID").getValue();

            var json = "[{";
            json = json + '"mListType":' + '"' + hdatatype + '",';//列表类型
            json = json + '"mSystemAppID":' + '"' + uID + '",';
            json = json + '"mDate1":' + '"' + cDate1 + '",';
            json = json + '"mDate2":' + '"' + cDate2 + '",';
            json = json + '"mCheckFlag":' + '"' + mCheckFlag + '",';
            json = json + '"mCorpItemID":' + '"' + mCorpItemID + '",';
            json = json + '"mCorpClassID":' + '"' + mCorpClassID + '",';
            json = json + '"mBillNo":' + '"' + mBillNo + '"';
            json = json + "}]";

            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;//导出
        }

        function onSelectionChanged(e) {
            var mgrid = e.sender;
            var record = mgrid.getSelected();
            if (record) {
                var mCheckFlag = record.FCheckFlag;
                if (!mCheckFlag) {
                    mini.get("removebill").setEnabled(true);
                }
                else {
                    mini.get("removebill").setEnabled(false);
                }
            }
        }

        function printdata() {
            var url = "../Report/PrintReport";
            mini.open({
                url: url,
                title: "打印", width: 1000, height: 700,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var NoneDisplayCol = [0];
                    var headtext = "";
                    if (hdatatype == "2")
                        headtext = "销售单据列表";
                    else
                        headtext = "销售退货单列表";
                    iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, parent.window.getSystemCompany() + headtext);
                }
            });
        }

    </script>

    </form>
</body>